home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_lib1 / rkrm_lib1.lha / GadTools / simplegtgadget.c < prev   
C/C++ Source or Header  |  1992-09-03  |  6KB  |  188 lines

  1. ;/* simplegtgadget.c -- execute me to compile me
  2. lc -b1 -cfistq -v -y -j73 simplegtgadget
  3. blink FROM LIB:c.o simplegtgadget.o TO simplegtgadget LIB LIB:lc.lib LIB:amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. /*
  34. Simple example of a GadTools gadget.  Compiled with SAS C v5.10a
  35. */
  36. #define INTUI_V36_NAMES_ONLY
  37.  
  38. #include <exec/types.h>
  39. #include <intuition/intuition.h>
  40. #include <intuition/gadgetclass.h>
  41. #include <libraries/gadtools.h>
  42.  
  43. #include <clib/exec_protos.h>
  44. #include <clib/intuition_protos.h>
  45. #include <clib/gadtools_protos.h>
  46.  
  47. #include <stdio.h>
  48.  
  49. #ifdef LATTICE
  50. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  51. int chkabort(void) { return(0); }  /* really */
  52. #endif
  53.  
  54. /* Gadget defines of our choosing, to be used as GadgetID's. */
  55. #define MYGAD_BUTTON    (4)
  56.  
  57. VOID process_window_events(struct Window *);
  58. VOID gadtoolsWindow(VOID);
  59.  
  60. struct TextAttr Topaz80 = { "topaz.font", 8, 0, 0, };
  61.  
  62. struct Library *IntuitionBase;
  63. struct Library *GadToolsBase;
  64.  
  65.  
  66. /*
  67. ** Open all libraries and run.  Clean up when finished or on error..
  68. */
  69. void main(void)
  70. {
  71. if ( (IntuitionBase = OpenLibrary("intuition.library", 37)) != NULL )
  72.     {
  73.     if ( (GadToolsBase = OpenLibrary("gadtools.library", 37)) != NULL )
  74.         {
  75.         gadtoolsWindow();
  76.  
  77.         CloseLibrary(GadToolsBase);
  78.         }
  79.     CloseLibrary(IntuitionBase);
  80.     }
  81. }
  82.  
  83.  
  84. /*
  85. ** Prepare for using GadTools, set up gadgets and open window.
  86. ** Clean up and when done or on error.
  87. */
  88. VOID gadtoolsWindow(VOID)
  89. {
  90. struct Screen    *mysc;
  91. struct Window    *mywin;
  92. struct Gadget    *glist, *gad;
  93. struct NewGadget ng;
  94. void             *vi;
  95.  
  96. glist = NULL;
  97.  
  98. if ( (mysc = LockPubScreen(NULL)) != NULL )
  99.     {
  100.     if ( (vi = GetVisualInfo(mysc, TAG_END)) != NULL )
  101.         {
  102.         /* GadTools gadgets require this step to be taken */
  103.         gad = CreateContext(&glist);
  104.  
  105.         /* create a button gadget centered below the window title */
  106.         ng.ng_TextAttr   = &Topaz80;
  107.         ng.ng_VisualInfo = vi;
  108.         ng.ng_LeftEdge   = 150;
  109.         ng.ng_TopEdge    = 20 + mysc->WBorTop + (mysc->Font->ta_YSize + 1);
  110.         ng.ng_Width      = 100;
  111.         ng.ng_Height     = 12;
  112.         ng.ng_GadgetText = "Click Here";
  113.         ng.ng_GadgetID   = MYGAD_BUTTON;
  114.         ng.ng_Flags      = 0;
  115.         gad = CreateGadget(BUTTON_KIND, gad, &ng, TAG_END);
  116.  
  117.         if (gad != NULL)
  118.             {
  119.             if ( (mywin = OpenWindowTags(NULL,
  120.                     WA_Title,     "GadTools Gadget Demo",
  121.                     WA_Gadgets,   glist,      WA_AutoAdjust,    TRUE,
  122.                     WA_Width,       400,      WA_InnerHeight,    100,
  123.                     WA_DragBar,    TRUE,      WA_DepthGadget,   TRUE,
  124.                     WA_Activate,   TRUE,      WA_CloseGadget,   TRUE,
  125.                     WA_IDCMP, IDCMP_CLOSEWINDOW |
  126.                               IDCMP_REFRESHWINDOW | BUTTONIDCMP,
  127.                     WA_PubScreen,   mysc,
  128.                     TAG_END)) != NULL )
  129.                 {
  130.                 GT_RefreshWindow(mywin, NULL);
  131.  
  132.                 process_window_events(mywin);
  133.  
  134.                 CloseWindow(mywin);
  135.                 }
  136.             }
  137.         /* FreeGadgets() must be called after the context has been
  138.         ** created.  It does nothing if glist is NULL
  139.         */
  140.         FreeGadgets(glist);
  141.         FreeVisualInfo(vi);
  142.         }
  143.     UnlockPubScreen(NULL, mysc);
  144.     }
  145. }
  146.  
  147. /*
  148. ** Standard message handling loop with GadTools message handling functions
  149. ** used (GT_GetIMsg() and GT_ReplyIMsg()).
  150. */
  151. VOID process_window_events(struct Window *mywin)
  152. {
  153. struct IntuiMessage *imsg;
  154. struct Gadget *gad;
  155. BOOL  terminated = FALSE;
  156.  
  157. while (!terminated)
  158.     {
  159.     Wait (1 << mywin->UserPort->mp_SigBit);
  160.  
  161.     /* Use GT_GetIMsg() and GT_ReplyIMsg() for handling */
  162.     /* IntuiMessages with GadTools gadgets.             */
  163.     while ((!terminated) && (imsg = GT_GetIMsg(mywin->UserPort)))
  164.         {
  165.         /* GT_ReplyIMsg() at end of loop */
  166.  
  167.         switch (imsg->Class)
  168.             {
  169.             case IDCMP_GADGETUP:       /* Buttons only report GADGETUP */
  170.                 gad = (struct Gadget *)imsg->IAddress;
  171.                 if (gad->GadgetID == MYGAD_BUTTON)
  172.                         printf("Button was pressed.\n");
  173.                 break;
  174.             case IDCMP_CLOSEWINDOW:
  175.                 terminated = TRUE;
  176.                 break;
  177.             case IDCMP_REFRESHWINDOW:
  178.                 /* This handling is REQUIRED with GadTools. */
  179.                 GT_BeginRefresh(mywin);
  180.                 GT_EndRefresh(mywin, TRUE);
  181.                 break;
  182.             }
  183.         /* Use the toolkit message-replying function here... */
  184.         GT_ReplyIMsg(imsg);
  185.         }
  186.     }
  187. }
  188.